package com.ruoyi.common.enums;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 文件格式枚举类
 */
public enum FileTypeEnum {
    IMAGE("image", "图片", new HashSet<>(Arrays.asList("png", "jpg", "jpeg", "gif", "bmp"))),
    VIDEO("video", "视频", new HashSet<>(Arrays.asList("mp4", "avi", "mov", "mkv"))),
    DOCUMENT("document", "文档", new HashSet<>(Arrays.asList("txt", "docx", "xlsx", "pdf", "ppt","doc"))),
    OTHER("other", "其他", new HashSet<>()); // 默认空集合

    private final String code;
    private final String name;
    private final Set<String> extensions;

    FileTypeEnum(String code, String name, Set<String> extensions) {
        this.code = code;
        this.name = name;
        this.extensions = extensions;
    }

    // 根据扩展名查找对应的文件类型
    public static FileTypeEnum fromExtension(String extension) {
        if (extension == null || extension.isEmpty()) {
            return OTHER;
        }
        String lowerExtension = extension.toLowerCase();
        for (FileTypeEnum type : values()) {
            if (type.extensions.contains(lowerExtension)) {
                return type;
            }
        }
        return OTHER;
    }

    // Getters
    public String getCode() { return code; }
    public String getName() { return name; }
}